package com.yxq.mdt.app.modules.socialcontact.adapter;

import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.modules.socialcontact.bean.SelectNearbyListBean;

import java.text.DecimalFormat;
import java.util.List;

public class NearbyAllListAdapter extends BaseQuickAdapter<SelectNearbyListBean.ListBean, BaseViewHolder> {

    public NearbyAllListAdapter(int layoutResId, @Nullable List<SelectNearbyListBean.ListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SelectNearbyListBean.ListBean item) {
        if (TextUtils.isEmpty(item.getResidence())) {
            helper.setGone(R.id.nearby_city_tv, false);
        } else {
            helper.setText(R.id.nearby_city_tv, item.getResidence());
        }
        if (item.getConstellation() == null || TextUtils.isEmpty(item.getConstellation())) {
            helper.setGone(R.id.nearby_constellation_tv, false);
        } else {
            helper.setText(R.id.nearby_constellation_tv, item.getConstellation());
        }
        if (item.getSex() == 1) {
            helper.setImageResource(R.id.social_like_sex_img, R.mipmap.xb_nan);
        } else {
            helper.setImageResource(R.id.social_like_sex_img, R.mipmap.xb_nv);
        }
        if (TextUtils.isEmpty(item.getGsName())) {
            helper.setGone(R.id.nearby_nike_name, false);
        } else {
            helper.setText(R.id.nearby_nike_name, item.getGsName());
        }
        if (item.getGeneration() != null || !TextUtils.isEmpty(item.getGeneration())) {
            helper.setText(R.id.nearby_introduce_tv, item.getGeneration());
        } else {
            helper.setText(R.id.nearby_introduce_tv, "");
        }
        if (item.getDistance() != 0 && item.getDistance() != 0.00) {
            if (item.getDistance() < 1000) {
                if ("0.0米".equals(String.format("%.1f米", item.getDistance()))) {
                    helper.setText(R.id.nearby_distance_tv, 0 + "米");
                } else {
                    helper.setText(R.id.nearby_distance_tv, String.format("%.1f米", item.getDistance()));
                }
            } else {
                helper.setText(R.id.nearby_distance_tv, String.format("%.1f km", item.getDistance() / 1000));
            }

        } else {
            helper.setText(R.id.nearby_distance_tv, 0 + "米");
        }
        helper.setGone(R.id.nearby_distance_tv, true);
        if (item.getRelation() == 1) {
            helper.setGone(R.id.nearby_attention_tv, false);
        } else {
            helper.setGone(R.id.nearby_attention_tv, true);
        }
        helper.setText(R.id.nearby_year_tv, "" + item.getAge() + "岁");
        GlideHelper.setLoadRoundImage(mContext, item.getHeadimg(), 0, helper.getView(R.id.nearby_nike_img));
        helper.addOnClickListener(R.id.nearby_nike_img);
        helper.addOnClickListener(R.id.nearby_attention_tv);
    }

}
